package com.pospi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.pospi.dto.CouponsBeen;
import com.pospi.pai.yunpos.R;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by acer on 2018/8/8.
 */

public class YhqAdapter extends BaseAdapter {
    private List<CouponsBeen> beens;
    private Context context;

    public YhqAdapter(List<CouponsBeen> beens, Context context) {
        this.beens = beens;
        this.context = context;
    }

    @Override
    public int getCount() {
        return beens.size();
    }

    @Override
    public Object getItem(int position) {
        return beens.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(context).inflate(R.layout.coupons_item, null);
            holder.je = convertView.findViewById(R.id.tv_je);
            holder.tj = convertView.findViewById(R.id.tv_tj);
            holder.rq = convertView.findViewById(R.id.tv_rq);
            holder.iv = convertView.findViewById(R.id.iv_select);
//                holder.tv_edqr = view.findViewById(R.id.tv_edqr);
            convertView.setTag(holder);

        } else {
            holder = (Holder) convertView.getTag();
        }
        DecimalFormat decimalFormat = new DecimalFormat("######.##########");
        holder.je.setText(decimalFormat.format(Double.parseDouble(beens.get(position).getDenomination())));
        holder.tj.setText("无门槛优惠券");
        String srq = beens.get(position).getStartt();
        String erq = beens.get(position).getEndt();
        holder.rq.setText("使用时间：" +srq.substring(srq.length()-5,srq.length())+"~"+erq.substring(erq.length()-5,erq.length()));
//            holder.tv_edqr.setText("截止日期：" + beens.get(i).getEndt());
        if (beens.get(position).isChoose()) {
            holder.iv.setVisibility(View.VISIBLE);
        } else {
            holder.iv.setVisibility(View.INVISIBLE);
        }

        return convertView;
    }
    class  Holder{
        TextView je;
        TextView tj;
        TextView rq;
        TextView tv_edqr;
        ImageView iv;
    }
}
